package cn.anjubao.cp.api.controller;

import cn.anjubao.cp.api.dto.LotInfoReqForm;
import cn.anjubao.cp.api.dto.SearchLotInfoReqForm;
import cn.anjubao.cp.api.dto.SlotNumStatusResDto;
import cn.anjubao.cp.api.service.ParkingLotService;
import cn.anjubao.cp.api.service.ParkingLotSlotService;
import cn.anjubao.cp.common.base.BaseResponse;
import cn.anjubao.cp.common.base.exception.BusinessException;
import com.anjubao.parking.municipal.parkinglot.dto.ParkingLotDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/lot")
public class ParkingLotController {
    @Autowired
    private ParkingLotService parkingLotService;
    @Autowired
    private ParkingLotSlotService parkingLotSlotService;

    /**
     * 根据经纬度获取车场信息
     * @param reqForm
     * @return
     */
    @PostMapping("/getLotInfo")
    public BaseResponse<List<ParkingLotDto>> getLotInfo(@Validated @RequestBody LotInfoReqForm reqForm){
        return BaseResponse.success(parkingLotService.getLotInfo(reqForm));
    }

    /**
     * 根据车场名称和地址搜索车场
     * @param reqForm
     * @return
     */
    @PostMapping("/searchLotInfo")
    public BaseResponse<List<ParkingLotDto>> searchLotInfo(@Validated @RequestBody SearchLotInfoReqForm reqForm){
        return BaseResponse.success(parkingLotService.searchLotInfo(reqForm));
    }

    /**
     * 检测车位状态
     * @param slotNum
     * @return
     */
    @GetMapping("/slot/{slotNum}/checkSlotNum")
    public BaseResponse<SlotNumStatusResDto> checkSlotNum(@PathVariable String slotNum) throws BusinessException {
        return BaseResponse.success(parkingLotSlotService.checkSlotNum(slotNum));
    }
}
